﻿using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace WPFDemoMVVM.ViewModel
{
    public partial class ItemControlViewModel :ObservableObject
    {
        public ObservableCollection<string> Stars { get; } = new ObservableCollection<string>() { "李四","张三","王五","赵六","七七","八八"};
    
        public ObservableCollection<Shape> Shapes { get; } = 
            new ObservableCollection<Shape>() 
            { 
                new Shape(0,new Point(50,50),Brushes.Red),
                new Shape(1,new Point(150,70),Brushes.Green),
                new Shape(1,new Point(300,160),Brushes.Blue),
                new Shape(0,new Point(240,260),Brushes.Yellow),
            };
        public ObservableCollection<FruitModel> Fruits { get; } =
               new ObservableCollection<FruitModel>()
               {
                 new Apple{Amount = 3},
                 new Apple{Amount = 2},
                 new Banana{Amount = 6},
                 new Apple{Amount = 4},
                 new Banana{Amount = 1},
                 new Banana{Amount = 5},
               };

        public ObservableCollection<Employee> Employees { get; } =
               new ObservableCollection<Employee>()
               {
                 new Employee("aa",Gender.Male),
                 new Employee("bb",Gender.Female),
                 new Employee("cc",Gender.Female),
                 new Employee("dd",Gender.Male),
                 new Employee("ee",Gender.Male),
               };

    }

    public record Shape(int Type,Point pos,Brush Color);

    public abstract class FruitModel
    {
        public int Amount { get; set; }
    }

    public class Apple: FruitModel
    {

    }
    public class Banana : FruitModel
    {

    }


    public record Employee(string Name,Gender Gender);
    public enum Gender
    {
        Male,
        Female,
    }

    public class EmployeeTemplateSelector : DataTemplateSelector
    {
        public DataTemplate MaleTemplate { get; set; }
        public DataTemplate FemaleTemplate { get; set; }
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var element = container as FrameworkElement;
            var employee = item as Employee;
            return employee?.Gender switch
            {
                Gender.Male => MaleTemplate,
                Gender.Female => FemaleTemplate,
                _ => throw new NotImplementedException()
            };
        }
    }

}
